package com.leyou.controller;

import com.leyou.entity.CartItem;
import com.leyou.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jshstart
 * @creat 2020-12-25 13:01
 */
@RestController
@RequestMapping("/cart")
public class TradeController {
    @Autowired
    private CartService cartService;
    @PostMapping
    public ResponseEntity<Void> saveCartItem(@RequestBody CartItem cartItem){
        cartService.saveCartItem(cartItem);
        return ResponseEntity.ok().build();
    }
    @GetMapping("/list")
    public ResponseEntity<List<CartItem>> queryAllCartItemBySort(){
        List<CartItem> list=cartService.queryAllCartItemBySort();
        return ResponseEntity.ok(list);
    }
    @PutMapping
    public ResponseEntity<Void> UpdateCartNum(@RequestParam("id") String id,
                                              @RequestParam("num") Integer num
                                              ){
        cartService.updateCartNum(id,num);
        return ResponseEntity.ok().build();
    }
    @DeleteMapping("/{skuId}")
    public ResponseEntity<Void> DeleteCartBySkuId(@PathVariable("skuId") Long skuId){
        cartService.deleteCartBySkuId(skuId);
        return ResponseEntity.ok().build();
    }
    @PostMapping("/list")
    public ResponseEntity<Void> addCartItemList(@RequestBody List<CartItem> list){
        cartService.addCartItemList(list);
        return ResponseEntity.ok().build();
    }
}
